<?php

session_start();
require_once "database.php";
error_reporting(0);
$result = mysql_query("SELECT * FROM tblsettings");
while($row = mysql_fetch_array($result))
{
$lang=$row[language];

#pre defined strings
$ip =$row[ip];
$docpath=$row[docpath];
$lansweeper=$row[lansweeper];
$status=$row[status];
$smtp=$row[smtp];
$itemails=$row[itemails];
$publicemails=$row[publicemails];
$domain=$row[domain];
$emailgroup=$row[emailgroup];
$defaultpro=$row[defaultpro];

$date=date("d/m/y", time()) ;
$datelog=date("dmy", time());

$yesterday=date("d", time())-1 ;
if($yesterday<10)
{
$yesterday='0'.$yesterday.date("/m/y", time()) ;
}
else
{
$yesterday=$yesterday.date("/m/y", time()) ;
}
$mtd='%'.date("/m/y", time()) ;
$lastmonth=date("m", time())-1 ;
if($lastmonth<10)
{
$lastmonth='%/0'.$lastmonth.'/'.date("y", time());
}
else
{
$lastmonth='%/'.$lastmonth.'/'.date("y", time());
}
$ytd='%/%/'.date("y", time());

$time=date("H:i:s", time()) ;
$user =$_SESSION["user"];

$title=$row[title];
$company =$row[company];
#$menustyle='images';
$databaseRev=$row[rev];
$sourceRev='3.6';
$preview=$row[preview];
$ldap=$row[ldap];
$ldapaddress=$row[ldapaddress];
$ldapuser=$row[ldapusername];
$ldappwd=$row[ldappassword];
$colourson=$row[colours];

#lock system strings
$publiclock=$row[publiclock];
$locked=$row['lock'];
$lockedreason=$row[lockreason];
}
$result = mysql_query("SELECT * FROM tblusers WHERE Name = '$user' ");
while($row = mysql_fetch_array($result))
{
$defaultgroup=$row['Default'];
}

if($locked=='true' & $bypasslock!=true)
{
echo '<center><H1>SYSTEM lOCKED!! '.$lockedreason.'</CENTER></H1>';
exit;
}




function genProirty()
{

$result = mysql_query("SELECT * FROM `tblProirty");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Name'].'</Option>';
}

}
function genStatus()
{
global $project;
$project='%'.$project.'%';
$result = mysql_query("SELECT * FROM tblstatus WHERE Project='all' OR Project LIKE '$project' ORDER BY Line");
while($row = mysql_fetch_array($result))
{
echo '<Option value="'.$row['Name'].'">'.$row['Name'].'</Option>';
}

}

function genApplications()
{

$result = mysql_query("SELECT * FROM tblapplications");
while($row = mysql_fetch_array($result))
{
echo '<Option value="'.$row['Name'].'">'.$row['Name'].'</Option>';
}

}

function genProjects()
{
global $user;
$user1='%'.$user.'%';
$result = mysql_query("SELECT * FROM tblprojects WHERE Users LIKE '%all%' OR Users LIKE '$user1'");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Name'].'</Option>';
}

}


function genDepartment()
{

$result = mysql_query("SELECT * FROM `tblDepartment");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Department'].'</Option>';
}
}

function genBranches()
{

$result = mysql_query("SELECT * FROM tblbranches Order By BranchNumber");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['BranchNumber'].'</Option>';
}
}

function genlinks()
{
global $user ;
global $lang_helpdesk;
global $lang_inventory;
global $lang_system;

$result = mysql_query("SELECT * FROM tblUsers WHERE Name='$user'");
$row = mysql_fetch_array($result);



echo '<option>All</option>';
$result = mysql_query("SELECT * FROM tblFolders Order By `key`");
while($row = mysql_fetch_array($result))
{
echo '<Option value="'.$row['Folder'].'">'.$row['Folder'].'</Option>';
}
}

function genOperator()
{

$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Name'].'</Option>';
}
}

function genFolder()
{

$result = mysql_query("SELECT * FROM `tblFolders");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Folder'].'</Option>';
}
}
function genType()
{

$result = mysql_query("SELECT * FROM tblinventorytype");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Type'].'</Option>';
}
}
function genKbFolders()
{

$result = mysql_query("SELECT * FROM `tblkbfolders");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Folder'].'</Option>';
}
}


function genSelect()
{
global $user ;
if($user=='')
    {
    $user='Public';
    }
$user1='%'.$user.'%';
$result = mysql_query("SELECT * FROM `tblSelect` WHERE `User`LIKE '$user1' OR User='all'");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Select'].'</Option>';
}
}


function genIStatus()
{

$result = mysql_query("SELECT * FROM tblInventoryStatus");
while($row = mysql_fetch_array($result))
{
echo '<Option>'.$row['Status'].'</Option>';
}

}

function gen1stline()
{
global $ip ;
mysql_query("Select * From tblJobs where Closed=' ' AND Line='1' ");
echo '1st Line : <b><a href=http://'.$ip.'/index.php?p=hfilter&f2=1st%20Line>', mysql_affected_rows() ,'</a></b>';
}
function gen2ndline()
{
global $ip ;
mysql_query("Select * From tblJobs where Closed=' ' AND Line='2' ");
echo '2nd Line : <b><a href=http://'.$ip.'/index.php?p=hfilter&f2=2nd%20Line>', mysql_affected_rows() ,'</b>';
}
function genOpen()
{
global $ip ;
mysql_query("Select * From tblJobs where Closed=' ' ");
echo 'Open : <b><a href=http://'.$ip.'/index.php?p=hfilter&f2=All%20Open>', mysql_affected_rows() ,"</b>";
}

function genCMA()
{
global $ip ;
mysql_query("Select * From tblJobs where Closed=' ' AND Branch LIKE'0%' ");
echo 'Plymouth : <b>', mysql_affected_rows() ,'</a></b>';

mysql_query("Select * From tblJobs where Closed=' ' AND Branch LIKE '2%' ");
echo '<br>Cornwall : <b>', mysql_affected_rows() ,'</a></b>';

mysql_query("Select * From tblJobs where Closed=' ' AND Branch LIKE '4%' ");
echo '<br>Exeter : <b>', mysql_affected_rows() ,'</a></b>';


}

function colourkey()
{
global $colour1stline;
  global $colour2ndLine;
  global $colouronHold;
  global $colourPending;
  global $colouroutOfHours;
  global $backgroundcolour;

echo '<table width="400px"><tr><td bgcolor="'.$colouronHold.'">On Hold</td><td bgcolor="'.$colouroutOfHours.'">Out of Hours</td><td bgcolor="'.$colour1stline.'">1st Line</td><td bgcolor="'.$colour2ndLine.'">2nd Line</td><td bgcolor="'.$colourPending.'">Pending</td></tr></table>';
}
function colourjobs()
{
  global $row;
  global $colourson;
  global $colour1stline;
  global $colour2ndLine;
  global $colouronHold;
  global $colourPending;
  global $colouroutOfHours;
  global $backgroundcolour;



 if ($colourson==true)
 {
 switch ($row[Status])
{
 

 case("Out of Hours Work");
 echo 'bgcolor="'.$colouroutOfHours.'"';
$colour=$colouroutOfHours;
$colours=true;
   break;

case("Pending");
 echo 'bgcolor="'.$colourPending.'" ';
$colour=$colourPending;
$colours=true;
   break;


}
switch ($row[Line])
{
 case("2");
 echo 'bgcolor="'.$colour2ndLine.'" ';
$colour=$colour2ndLine;
$colours=true;
   break;
case("1");
 echo 'bgcolor="'.$colour1stline.'"';
$colour=$colour1stline;
$colours=true;
   break;
case("3");
 echo 'bgcolor="'.$colouronHold.'" ';
$colour=$colouronhold;
$colours=true;
   break;
}
if ($colours)
{


$colour=$backgroundcolour;
$colours=false;

}
 }
else
{
$colour=$backgroundcolour;
$colours=false;
}
}
?>